package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.StaticData;
import com.sc.nft.entity.vo.ecology.AdminSmeltingImageVO;
import com.sc.nft.mapper.StaticDataMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * (sc_static_data)数据DAO
 *
 * @author Sun
 * @description 由 Mybatisplus Code Generator 创建
 * @since 2022-05-29 17:37:58
 */
@Slf4j
@Repository
public class StaticDataDao extends ServiceImpl<StaticDataMapper, StaticData> {

    public StaticData getByType(String type) {
        LambdaQueryWrapper<StaticData> staticDataWrapper = new LambdaQueryWrapper<>();
        staticDataWrapper.eq(StaticData::getType, type);
        return getOne(staticDataWrapper);
    }

    public List<StaticData> getListByType(String type) {
        LambdaQueryWrapper<StaticData> staticDataWrapper = new LambdaQueryWrapper<>();
        staticDataWrapper.likeRight(StaticData::getType, type);
        return list(staticDataWrapper);
    }


    public Boolean updateStaticData(String type, String value) {
        UpdateWrapper<StaticData> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("type", type);
        updateWrapper.set("value", value);
        return update(new StaticData(),updateWrapper);
    }

    public List<StaticData> getByTypes(List<String> type) {
        LambdaQueryWrapper<StaticData>queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.in(StaticData::getType,type);
        List<StaticData> staticData = baseMapper.selectList(queryWrapper);
        return staticData;
    }

    public List<AdminSmeltingImageVO> getListByType() {
        return baseMapper.getListByType();
    }
}